var t = require("../../@babel/runtime/helpers/createForOfIteratorHelper"),
  e = require("../../utils/http.js"),
  a = require("../../utils/api.js");
Page({
  data: {
    unList: [],
    returnList: [],
    isShowPeople: !1,
    isDown: !1,
    chooseList: [],
    chooseId: [],
    chooseData: {},
    totalPrice: 0,
    code: "",
  },
  onLoad: function (t) {
    this.getCustomerUserList({
      orderSn: t.orderSn,
      merchantNo: wx.getStorageSync("merchantNo"),
    }),
      this.setData({ orderSn: t.orderSn });
  },
  Expand: function () {
    this.setData({ isDown: !this.data.isDown });
  },
  getValue: function (t) {
    this.setData({ code: t.detail.value });
  },
  cancel: function (t) {
    var e = t.currentTarget.dataset.id,
      a = t.currentTarget.dataset.idx,
      o = t.currentTarget.dataset.price,
      s = this.data.chooseData,
      i = this.data.chooseId,
      r = this.data.chooseList,
      n = this.data.totalPrice;
    r.splice(a, 1), delete s[e], (n = (parseFloat(n) - o).toFixed(2));
    for (var c = 0; c < i.length; c++)
      if (i[c] == e) {
        i.splice(c, 1);
        break;
      }
    this.setData({ chooseData: s, chooseId: i, chooseList: r, totalPrice: n });
  },
  lookPeople: function () {
    this.setData({ isShowPeople: !this.data.isShowPeople });
  },
  changeOrder: function (e) {
    var a = {},
      o = this.data.unList,
      s = [],
      i = 0,
      r = e.detail.value;
    if (r.length > 0) for (var n = 0; n < r.length; n++) a[r[n]] = !0;
    else a = {};
    var c,
      h = t(o);
    try {
      for (h.s(); !(c = h.n()).done; ) {
        var d = c.value;
        a[d.id] &&
          (s.push(d), (i = (parseFloat(i) + d.productPrice).toFixed(2)));
      }
    } catch (t) {
      h.e(t);
    } finally {
      h.f();
    }
    this.setData({ chooseId: r, chooseData: a, chooseList: s, totalPrice: i });
  },
  checkAll: function () {
    var e = this.data.unList,
      a = [],
      o = 0,
      s = this.data.chooseData,
      i = this.data.chooseId;
    if (e.length == i.length)
      this.setData({
        chooseData: {},
        chooseId: [],
        totalPrice: 0,
        chooseList: [],
      });
    else {
      (i = []), (s = {});
      var r,
        n = t(e);
      try {
        for (n.s(); !(r = n.n()).done; ) {
          var c = r.value;
          (s[c.id] = !0),
            i.push(c.id),
            a.push(c),
            (o = (parseFloat(o) + c.productPrice).toFixed(2));
        }
      } catch (t) {
        n.e(t);
      } finally {
        n.f();
      }
      this.setData({
        chooseData: s,
        chooseId: i,
        chooseList: a,
        totalPrice: o,
      });
    }
  },
  confirm: function () {
    var t = this;
    0 != t.data.chooseId.length
      ? wx.showModal({
          title: "提示",
          content: "确认要取消选中的名单吗？",
          success: function (a) {
            if (a.confirm) {
              wx.showLoading({ title: "取消中..." });
              var o = {
                orderSn: t.data.orderSn,
                merchantNo: t.data.merchantNo,
                orderUserId: t.data.chooseId,
              };
              console.log(o, "param"),
                e
                  .CancelOrder(o)
                  .then(function (e) {
                    var a = getCurrentPages(),
                      o = a[a.length - 2];
                    console.log(a),
                      o.getOrderDetail({ orderSn: t.data.orderSn }),
                      wx.setStorageSync("isRefresh", !0),
                      wx.hideLoading(),
                      wx.reLaunch({
                        url: "plugin-private://wx393d60d93f70599c/pages/order/index",
                      });
                  })
                  .catch(function (t) {
                    wx.hideLoading();
                  });
            }
          },
        })
      : a.showMsg("请先选择需要取消的人员");
  },
  Search: function () {
    this.getCustomerUserList({
      orderSn: this.data.orderSn,
      keyWords: this.data.code,
    });
  },
  getCustomerUserList: function (t) {
    var o = this;
    e.getCustomerUserList(t).then(function (e) {
      "" == t.keyWords || 0 != e.data.waitList.length
        ? o.setData({ unList: e.data.waitList, returnList: e.data.refueList })
        : a.showMsg("未搜索到内容");
    });
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
});
